package com.train.generator;

import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
import java.util.Random;

import com.train.entity.Locomotive;
import com.train.entity.Train;
import com.train.entity.Wagon;
import com.train.utils.Generator;

public class Depo {

	private Locomotive locomotive;
	private int wagonsAmount;
	
	
	
	public Depo(Locomotive locomotive, int wagonsAmount) {
		super();
		this.locomotive = locomotive;
		this.wagonsAmount = wagonsAmount;
	}

	public Locomotive getLocomotive() {
		return locomotive;
	}

	public void setLocomotive(Locomotive locomotive) {
		this.locomotive = locomotive;
	}

	public int getWagonsAmount() {
		return wagonsAmount;
	}

	public void setWagonsAmount(int wagonsAmount) {
		this.wagonsAmount = wagonsAmount;
	}

	public Train wagons() {
		Train train = new Train(locomotive);
		List<Wagon> wagons = new LinkedList<Wagon>();
		Random random = new Random();
		int randomNumberComfort = 0;
		int randomNumberPassengers = 0;
		for (int i=1; i<=wagonsAmount; i++) {
			randomNumberComfort = random.nextInt(4 - 1) + 1;
			randomNumberPassengers = random.nextInt(50 - 30) + 30;			
			wagons.add(new Wagon(Generator.generateId(), randomNumberComfort, randomNumberPassengers));			
		}
		Collections.sort(wagons);
		train.setWagons(wagons);
		return train;
	}
	
}
